package cn.gson.crm.controller.employee;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.EmpDao;
import cn.gson.crm.model.entity.Employee;

/**
 * 删除部门
 */
@WebServlet("/employee/empdelete")
public class EmpDeleteServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private EmpDao empDao = new EmpDao();
	private String empName = "";

	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String[] ids = request.getParameterValues("id");
		for (String id : ids) {
			Employee emp = empDao.getUserById(id);
			if (emp.getEmpStatus() == 1) {
				boolean result = empDao.EmpDelete(0, id);
				if (!result) {
					empName += id;
					// errorForward("删除错误", "employee");
				}
			}else {
				boolean result = empDao.EmpDelete(1, id);
				if (!result) {
					empName += id;
					// errorForward("删除错误", "employee");
				}
			}
		}
		request.getSession().setAttribute("empName", empName);
		redirect("employee");
	}

}
